<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>${empty student ? '添加学生' : '修改学生信息'}</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            padding: 30px;
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
            font-size: 28px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: bold;
        }

        .required {
            color: red;
        }

        input[type="text"],
        input[type="date"],
        select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
            transition: border-color 0.3s;
        }

        input[type="text"]:focus,
        input[type="date"]:focus,
        select:focus {
            outline: none;
            border-color: #667eea;
        }

        .btn-container {
            margin-top: 30px;
            text-align: center;
        }

        .btn {
            display: inline-block;
            padding: 12px 40px;
            margin: 0 10px;
            background: #667eea;
            color: white;
            text-decoration: none;
            border-radius: 5px;
            transition: background 0.3s;
            border: none;
            cursor: pointer;
            font-size: 16px;
        }

        .btn:hover {
            background: #5568d3;
        }

        .btn-secondary {
            background: #6c757d;
        }

        .btn-secondary:hover {
            background: #5a6268;
        }

        .error-message {
            background: #f8d7da;
            color: #721c24;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>${empty student ? '添加学生' : '修改学生信息'}</h1>

        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>

        <form action="${pageContext.request.contextPath}/student" method="post">
            <input type="hidden" name="action" value="${empty student ? 'save' : 'update'}">
            <c:if test="${not empty student}">
                <input type="hidden" name="id" value="${student.id}">
            </c:if>

            <div class="form-group">
                <label for="pId">身份证号 <span class="required">*</span></label>
                <input type="text" id="pId" name="pId" value="${student.pId}" 
                       required maxlength="32" placeholder="请输入身份证号">
            </div>

            <div class="form-group">
                <label for="no">学号 <span class="required">*</span></label>
                <input type="text" id="no" name="no" value="${student.no}" 
                       required maxlength="32" placeholder="请输入学号">
            </div>

            <div class="form-group">
                <label for="name">姓名 <span class="required">*</span></label>
                <input type="text" id="name" name="name" value="${student.name}" 
                       required maxlength="20" placeholder="请输入姓名">
            </div>

            <div class="form-group">
                <label for="sex">性别 <span class="required">*</span></label>
                <select id="sex" name="sex" required>
                    <option value="">请选择性别</option>
                    <option value="男" ${student.sex == '男' ? 'selected' : ''}>男</option>
                    <option value="女" ${student.sex == '女' ? 'selected' : ''}>女</option>
                </select>
            </div>

            <div class="form-group">
                <label for="birthdate">出生日期 <span class="required">*</span></label>
                <input type="date" id="birthdate" name="birthdate" 
                       value="<fmt:formatDate value='${student.birthdate}' pattern='yyyy-MM-dd'/>" 
                       required>
            </div>

            <div class="btn-container">
                <button type="submit" class="btn">提交</button>
                <a href="${pageContext.request.contextPath}/student?action=list" class="btn btn-secondary">取消</a>
            </div>
        </form>
    </div>
</body>
</html>

